package pkg.chemdrm;

import javax.microedition.khronos.opengles.GL10;

import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.text.Text;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.util.HorizontalAlign;

public class InventoryObject extends Sprite
{
	boolean mIsSelected; // whether it is selected in the inventory or not
	Substance mSubstance; // substance associated with the icon
	Text mText;
	
	public InventoryObject(float x, float y, Font pFont, TextureRegion pTextureRegion, Substance pSubstance) 
	{
		super(x, y, 64, 64, pTextureRegion);
		mSubstance = pSubstance;

		
		//mText = new Text(0, 68, pFont, pSubstance.mName, HorizontalAlign.CENTER);
		
		//for chemical names
		if(pSubstance.mName.length() == 8)
		{
			mText = new Text(4, 68, pFont, pSubstance.mName, HorizontalAlign.CENTER);
		}
		else if(pSubstance.mName.length() == 6)
		{
			mText = new Text(10, 68, pFont, pSubstance.mName, HorizontalAlign.CENTER);
		}
		else if(pSubstance.mName.length() == 5)
		{
			mText = new Text(14, 68, pFont, pSubstance.mName, HorizontalAlign.CENTER);
		}
		else if(pSubstance.mName.length() == 4)
		{
			mText = new Text(20, 68, pFont, pSubstance.mName, HorizontalAlign.CENTER);
		}
		mText.setWidth(64);
		
		//mText.setScale(0.5f);
		attachChild(mText);
	}

	public void touch()
	{

		if(mIsSelected)
		{
			mIsSelected = false;
			this.setColor(1f, 1f, 1f);
		}
		else
		{
			mIsSelected = true;
		
			this.setColor(0.5f, 0.5f, 0.0f);

		}
	}
}
